#include"Object.h"
void AddNode(LIST &list,Object object)
{
	NODE *node;
	node= new NODE;
	if(node==NULL) exit(1);
	node->object=object;
	node->stt=list.n;
	node->next=NULL;
		
	if(list.pHead==NULL) 
	{
		list.pHead=node;
		list.pTail=list.pHead;
	}
	else
	{
		node->next=list.pHead;
		list.pHead=node;
		/*list.pTail->next=node;
		list.pTail=node;*/
	}
	list.n++;
}
void RemoveHead(LIST &list)
{
	NODE *p;
	if(list.pHead!=NULL)
	{
		p=list.pHead;
		list.pHead=list.pHead->next;
		delete p;
		if(list.pHead==NULL) list.pTail=NULL;
	}
}
void RemoveTail(LIST &list)
{
	NODE *p;
	p=list.pHead;
	while(p->next!=NULL&&p->next->next!=NULL) p=p->next;
	p->next=NULL;
	delete list.pTail;
	list.pTail=p;
	
	//delete (p->next);
}
void  RemoveNode(LIST &list,int t)
{
	int i=0;
	NODE *q=NULL;
	NODE *p=list.pHead;
	while(p!=NULL)
	{
		if(t==p->stt) break;
		q=p;
		p=p->next;
	}
	if(p==NULL) return;
	if(q!=NULL)
	{
		if(p==list.pTail) list.pTail=q;
		q->next=p->next;
		delete p;
	}
	else
	{
		list.pHead=p->next;
		if(list.pHead==NULL) list.pTail=NULL;
	}
	list.n--;
	/*
	if(q!=list.pHead)
	{
		if(q->next!=NULL)
			{
				q->object=q->next->object;
				if(q->next->next==NULL)
				{
					q->next=NULL;
					list.pTail=q;
					delete q->next;
				}
				else 
				{
					NODE *tam=q->next->next;
					delete (q->next);
					q->next=tam;
				}
				
			}
		else RemoveTail(list);
	}
	else
	{
		RemoveHead(list);
	}*/
	/*NODE *tam;
	NODE *p;
	tam=list.pHead;
	while(tam->next!=NULL&&tam->next!=q) tam=tam->next;
	if(tam!=NULL)
	{
		p=tam->next;
		if(p!=NULL)
		{
		if(p==list.pTail) list.pTail=tam;
		else tam->next=p->next;
		delete p;
		}
	}
	else
	{
		RemoveHead(list);
	}
	
	if(q!=NULL)
	{
		tam=q->next; 
		if(tam!=NULL)
		{
			if(tam==list.pTail) list.pTail=q;
			q->next=tam->next;
			delete tam;
		}
	}
	else
	{
		RemoveHead(list);
	}
	*/

}
/*
void AddGoomba(LIST_GOOMBA &list,CGoomba *goomba)
{
	NODE_GOOMBA *p;
	p=new NODE_GOOMBA;
	if(p==NULL) exit(1);
	p->goomba=goomba;
	p->next=NULL;
	if(list.pHead==NULL)
	{
		list.pHead=p;
		list.pTail=list.pHead;
	}
	else
	{
		p->next=list.pHead;
		list.pHead=p;
	}
}
void AddKoopa(LIST_KOOPA &list,CKoopa *koopa)
{
	NODE_KOOPA *p;
	p=new NODE_KOOPA;
	if(p==NULL) exit(1);
	p->koopa=koopa;
	p->next=NULL;
	if(list.pHead==NULL)
	{
		list.pHead=p;
		list.pTail=list.pHead;
	}
	else
	{
		p->next=list.pHead;
		list.pHead=p;
	}
}
void AddPirana(LIST_PIRANA &list,CPirana *pirana)
{
	NODE_PIRANA *p;
	p=new NODE_PIRANA;
	if(p==NULL) exit(1);
	p->pirana=pirana;
	p->next=NULL;
	if(list.pHead==NULL)
	{
		list.pHead=p;
		list.pTail=list.pHead;
	}
	else
	{
		p->next=list.pHead;
		list.pHead=p;
	}
}*/